//
//  YZDoctorBaseInfoView.m
//  kuaiyi
//
//  Created by WGP on 16/5/5.
//
//

#import "YZDoctorBaseInfoView.h"
#import "YZDoctorModel.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>

@interface YZDoctorBaseInfoView ()

@property(nonatomic,weak)UIImageView *iconView;
@property(nonatomic,weak)UILabel *doctorNameLabel;
@property(nonatomic,weak)UILabel *doctorProfessionLabel;
@property(nonatomic,weak)UILabel *departmentLabel;
@property(nonatomic,strong)UIButton *operationCount;
@property(nonatomic,strong)UIButton *flowerCount;
@property(nonatomic,strong)UIButton *bannerCount;
@property(nonatomic,strong)UIImageView *firseLine;
@property(nonatomic,strong)UIImageView *secondLine;

@end
@implementation YZDoctorBaseInfoView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
    self.backgroundColor = [UIColor whiteColor];
//    添加空间
    UIImageView *iconView = [[UIImageView alloc] init];
    self.iconView = iconView;
    self.iconView.layer.cornerRadius = 30;
    self.iconView.layer.masksToBounds = YES;
    [self addSubview:iconView];
    
    UILabel *nameLabel = [[UILabel alloc] init];
    self.doctorNameLabel = nameLabel;
    [self addSubview:nameLabel];
    nameLabel.font = [UIFont systemFontOfSize:14];
    
    UILabel *doctorProfessionLabel = [[UILabel alloc] init];
    self.doctorProfessionLabel = doctorProfessionLabel;
    [self addSubview:doctorProfessionLabel];
    doctorProfessionLabel.font = [UIFont systemFontOfSize:14];
    
    UILabel *departmentLabel = [[UILabel alloc] init];
    [self addSubview:departmentLabel];
    self.departmentLabel = departmentLabel;
    departmentLabel.textColor = [UIColor lightGrayColor];
    departmentLabel.font = [UIFont systemFontOfSize:14];
    
    self.operationCount = [self buttonWith:@"yuyueliang"];
    
    self.firseLine = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_img_line.png"]];
    [self addSubview:self.firseLine];
    
    self.flowerCount = [self buttonWith:@"xianhua"];
    
    self.secondLine = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_img_line.png"]];
    [self addSubview:self.secondLine];
    
    self.bannerCount = [self buttonWith:@"jinqi"];
  
//    添加约束
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.left.equalTo(self).offset(20);
        make.width.height.mas_equalTo(60);
    }];
    
    [self.doctorNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(10);
        make.top.equalTo(self.iconView);
    }];
    
    [self.departmentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.doctorNameLabel);
        make.top.equalTo(self.doctorNameLabel.mas_bottom).offset(10);
    }];
    
    [self.doctorProfessionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.doctorNameLabel);
        make.left.equalTo(self.doctorNameLabel.mas_right).offset(30);
    }];
    [self.operationCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView);
        make.bottom.equalTo(self).offset(-5);
    }];
    
    [self.firseLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.operationCount);
        make.left.mas_equalTo([UIScreen mainScreen].bounds.size.width/3);
    }];
    
    [self.flowerCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self).offset(-5);
    }];
    
    [self.secondLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.flowerCount);
        make.left.mas_equalTo([UIScreen mainScreen].bounds.size.width/3 * 2);
    }];
    
    [self.bannerCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-20);
        make.bottom.equalTo(self).offset(-5);
    }];
}

-(void)setDoctorModel:(YZDoctorModel *)doctorModel
{
    _doctorModel = doctorModel;
    
    [self.iconView sd_setImageWithURL:doctorModel.doctor_portraitURL placeholderImage:[UIImage imageNamed:@"illness_img_person.png"]];
    self.doctorNameLabel.text = doctorModel.doctor_name;
    self.doctorProfessionLabel.text = doctorModel.doctor_title_name;
    self.departmentLabel.text = [NSString stringWithFormat:@"%@-变态反应科门诊",doctorModel.doctor_hospital_name];
    [self.operationCount setTitle:[NSString stringWithFormat:@"预约量:%zd",[doctorModel.operation_count intValue]] forState:UIControlStateNormal];
     [self.flowerCount setTitle:[NSString stringWithFormat:@"预约量:%zd",[doctorModel.flower intValue]] forState:UIControlStateNormal];
     [self.bannerCount setTitle:[NSString stringWithFormat:@"预约量:%zd",[doctorModel.banner intValue]] forState:UIControlStateNormal];
}

-(UIButton *)buttonWith:(NSString *)imageName
{
    UIButton *btn = [[UIButton alloc] init];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    btn.userInteractionEnabled = NO;
    [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [btn sizeToFit];
    [self addSubview:btn];
    return btn;
}

@end


















